Public Class cAlboIncassi
    'getElencoIncassi
    'restituisce la tabella con i movimenti di un iscritto
    Public Shared Function getElencoIncassi(ByVal __idAna As Integer, ByVal __idAlbo As Integer, ByVal __pagato As Byte) As DataTable
        Dim sql As String
        sql = "SELECT Id, IdAlboIncassiTipo, DataPagamento, IdAlboIncassiMetodoPagamento, IdEmissione, FlussoId, Data, Oggetto, Importo, DataScadenza, Pagato = CASE WHEN DataPagamento IS NULL THEN 'No' ELSE 'Si' END FROM AlboIncassi "
        sql += "WHERE (IdAnagrafica = " & __idAna & ") AND (IdAlbo = " & __idAlbo & ") "
        Select Case __pagato
            Case 0
                sql += "AND DataPagamento IS NOT NULL "
            Case 1
                sql += "AND DataPagamento IS NULL "
        End Select
        sql += " order by Data desc"
        Dim cn As New SICOP.Classi.DALBase.cConnessione
        Return cn.getDataTable(sql)
    End Function
    Public Shared Function InsertIncassoInDB(ByVal __IdAnagrafica As Integer, ByVal __IdAlbo As Integer, ByVal __IdAlboIncassiTipo As Integer, ByVal __Data As Date, ByVal __Oggetto As String, ByVal __Importo As Decimal, ByVal __DataScadenza As Date, ByVal __DataPagamento As Date, ByVal __IdAlboIncassiMetodoPagamento As Integer) As String
        Dim sql As String = "INSERT INTO AlboIncassi ( IdAnagrafica, IdAlbo, IdAlboIncassiTipo, Data, Oggetto, Importo, DataScadenza, DataPagamento, IdAlboIncassiMetodoPagamento) "
        sql += "VALUES (@IdAnagrafica, @IdAlbo, @IdAlboIncassiTipo, @Data, @Oggetto, @Importo, @DataScadenza, @DataPagamento, @IdAlboIncassiMetodoPagamento);"
        Dim cmSql As New Data.SqlClient.SqlCommand(sql)
        cmSql.Parameters.Add("@IdAnagrafica", Data.SqlDbType.Int, 4)
        cmSql.Parameters.Add("@IdAlbo", Data.SqlDbType.SmallInt, 2)
        cmSql.Parameters.Add("@IdAlboIncassiTipo", Data.SqlDbType.TinyInt, 1)
        cmSql.Parameters.Add("@Data", Data.SqlDbType.DateTime, 8)
        cmSql.Parameters.Add("@Oggetto", Data.SqlDbType.NVarChar, 50)
        cmSql.Parameters.Add("@Importo", Data.SqlDbType.Money, 8)
        cmSql.Parameters.Add("@DataScadenza", Data.SqlDbType.DateTime, 8)
        cmSql.Parameters.Add("@DataPagamento", Data.SqlDbType.DateTime, 8)
        cmSql.Parameters.Add("@IdAlboIncassiMetodoPagamento", Data.SqlDbType.TinyInt, 1)

        cmSql.Parameters("@IdAnagrafica").Value = __IdAnagrafica
        cmSql.Parameters("@IdAlbo").Value = __IdAlbo
        cmSql.Parameters("@IdAlboIncassiTipo").Value = __IdAlboIncassiTipo
        cmSql.Parameters("@Data").Value = __Data
        cmSql.Parameters("@Oggetto").Value = __Oggetto
        cmSql.Parameters("@Importo").Value = __Importo
        cmSql.Parameters("@DataScadenza").Value = __DataScadenza
        If __IdAlboIncassiMetodoPagamento > 0 Then
            cmSql.Parameters("@DataPagamento").Value = __DataPagamento
            cmSql.Parameters("@IdAlboIncassiMetodoPagamento").Value = __IdAlboIncassiMetodoPagamento
        Else
            cmSql.Parameters("@DataPagamento").Value = System.DBNull.Value
            cmSql.Parameters("@IdAlboIncassiMetodoPagamento").Value = System.DBNull.Value
        End If
        Dim cn As New SICOP.Classi.DALBase.cConnessione
        InsertIncassoInDB = cn.runSqlCommandNoReturnValue(cmSql)
    End Function
    Public Shared Function UpdateIncassoInDB() As String
        UpdateIncassoInDB = ""
    End Function
End Class
